import { queryFloorPage } from '@/pages/data/qrcode_floor/service';

export default {
  namespace: 'qrcode_floor',

  state: {
    list: { data: [] },
    floorList: { data: [] },
    details: [],
    cond: {},
    subCond: {},
    dict: {}
  },

  effects: {
    *updateSubCond({ payload = { pageNum: 1, pageSize: 10 } }, { put }) {
      const { pageSize, pageNum, ...cond } = payload;
      yield put({ type: 'setSubCond', payload: cond });
      yield put({ type: 'floorPage', payload });
    },
    *floorPage({ payload }, { call, put, select }) {
      const cond = yield select(state => state.qrcode_floor.subCond);
      const params = { ...payload, ...cond };
      const { list = [], total } = yield call(queryFloorPage, params);
      yield put({ type: 'setFloorPage', payload: { list, total } })
    }
  },

  reducers: {
    setSubCond(state, action) {
      return {
        ...state,
        subCond: action.payload
      }
    },
    setFloorPage(state, action) {
      return {
        ...state,
        floorList: {
          data: action.payload.list,
          dataCnt: action.payload.total
        }
      }
    }
  }
}
